package com.drx.schedule;

import com.drx.service.ReservationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

@Component
public class Myschedule {
    @Autowired
    ReservationService reservationService;

    private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
    //每隔2秒执行一次

    //每天3：05执行
    @Scheduled(cron = "0 0 8-23 * * ?")
    public void testTasks() {
        System.out.println("定时任务执行时间：" + dateFormat.format(new Date()));
        //执行定时任务，每一个小时检查tabRecord表，将过期的预约状态设置为'n'
        reservationService.checkExpiredReservat(Integer.parseInt(new SimpleDateFormat("HH").format(new Date())));
    }
}
